import requests
import json
async def call_qianfan(prompt: str) -> str:
    """
    模拟 GPT 返回结果
    """
    # 简单返回一个固定字符串或者根据 prompt 返回一些内容
    url = "https://qianfan.baidubce.com/v2/app/conversation/runs"
    
    payload = json.dumps({
        "app_id": "6938253c-29d2-45ca-9fe6-55b129a3458f",
        "query": prompt,
        "conversation_id": "a47ded8f-e089-40f7-b731-2a6da55bb153",
        "stream": False
    }, ensure_ascii=False)
    
    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer bce-v3/ALTAK-fZ40fndqmmN697ZxYQSCp/ee8e4aaf7ef47249351767501e8320ed31b2a2d3'
    }
    
    response = requests.post(url, headers=headers, data=payload.encode("utf-8"))
    
    if response.status_code == 200:
        data = response.json()
        # 提取回复内容
        answer = data.get("answer", "")

        return f"[ qianfan 回复] : {answer}"
    else:
        print("请求失败，状态码：", response.status_code)
        print("响应内容：", response.text)

    return f"[模拟 GPT 回复] 你发送的内容是: {prompt}"
